<?php

namespace App\Models;

use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;

/**
 * App\Models\User
 *
 * @property int $id
 * @property string $username
 * @property string $password
 * @property string $phone
 * @property string $email 邮箱
 * @property string $avatar
 * @property int|null $status 用户状态
 * @property int $created_date 创建日期
 * @property \Illuminate\Support\Carbon $created_at
 * @property \Illuminate\Support\Carbon $updated_at
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Category[] $category
 * @property-read int|null $category_count
 * @property-read \App\Models\UserQq $userQq
 * @property-read \App\Models\UserWeixin $userWeixin
 * @method static \Illuminate\Database\Eloquent\Builder|User newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|User newQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|User query()
 * @method static \Illuminate\Database\Eloquent\Builder|User whereAvatar($value)
 * @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|User whereCreatedDate($value)
 * @method static \Illuminate\Database\Eloquent\Builder|User whereEmail($value)
 * @method static \Illuminate\Database\Eloquent\Builder|User whereId($value)
 * @method static \Illuminate\Database\Eloquent\Builder|User wherePassword($value)
 * @method static \Illuminate\Database\Eloquent\Builder|User wherePhone($value)
 * @method static \Illuminate\Database\Eloquent\Builder|User whereStatus($value)
 * @method static \Illuminate\Database\Eloquent\Builder|User whereUpdatedAt($value)
 * @method static \Illuminate\Database\Eloquent\Builder|User whereUsername($value)
 * @mixin \Eloquent
 */
class User extends Authenticatable implements JWTSubject
{
    protected $table = 'user';

    protected $primaryKey = 'id';

    protected $fillable = ['username', 'password', 'phone', 'email', 'avatar', 'created_date'];

    /*
     * 常量定义
     */
    // 登录方式
    const LOGIN_TYPE_ACCOUNT = 1;
    const LOGIN_TYPE_PHONE = 2;
    const LOGIN_TYPE_QQ = 3;
    const LOGIN_TYPE_WEIXIN = 4;

    public static $loginType = [
        self::LOGIN_TYPE_ACCOUNT => '账号密码登录',
        self::LOGIN_TYPE_PHONE => '手机号登录',
        self::LOGIN_TYPE_QQ => 'QQ登录',
        self::LOGIN_TYPE_WEIXIN => '微信登录',
    ];

    // 用户状态
    const USER_STATUS_NORMAL = 0; // 正常
    const USER_STATUS_FORBIDDEN = -1; //禁止

    /**
     * jwt
     */
    public function getJWTIdentifier()
    {
        return $this->getKey();
    }

    public function getJWTCustomClaims()
    {
        return [];
    }

    /**
     * 模型关联
     */
    public function userQq()
    {
        return $this->hasOne(UserQq::class,'user_id','id')->withDefault();
    }

    public function userWeixin()
    {
        return $this->hasOne(UserWeixin::class,'user_id','id')->withDefault();
    }

    public function category()
    {
        return $this->hasMany(Category::class,'user_id','id');
    }




}
